package com.zhongnan.demo2;

public class ArrayEqual {
    public static void main(String[] args) {
        int[] arr = {5, 8, 1, 6, 7, 3};
        // 自己的写法
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                int num;
                if (arr[i] > arr[j]) {
                    num = arr[i];
                    arr[i] = arr[j];
                    arr[j] = num;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        // 视频的写法
        int[] arr1 = {5, 8, 1, 6, 7, 3};
        for (int i = 0; i < arr1.length - 1; i++) {
            for (int j = 0; j < arr1.length - 1 - i; j++) {
                if (arr1[j] > arr1[j+1]) {
                    int num = arr1[j];
                    arr1[j] = arr1[j+1];
                    arr1[j+1] = num;
                }
            }
        }
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }
    }
}
